/*
 * ServerT.cpp
 *
 *  Created on: May 27, 2011
 *      Author: stud
 */
#include <iostream>
#include <string.h>
#include "Thread.h"
#include "ServerSocket.h"
#include "SocketException.h"

#include "ServerThread.h"

ServerT::ServerT(ThreadPriority pri, string _name, ServerSocket *ss) :
	Thread(pri, _name) {
	new_sock = ss;
}

void ServerT::run ()
{
	int cnt;
	char buf[100];
	try {
		while (true) {
			std::string data;
			cnt = new_sock->recv(data);
			strncpy(buf, data.c_str(), cnt);
			std::cout << "Got:" << cnt << " " << buf << "\n";
			new_sock->send(data);
		}
	} catch (SocketException&) {
	}

}

ServerT::~ServerT() {
	delete(new_sock);
}

